package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Elder;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.ElderFamilyDto;
import com.zzyl.nursing.dto.ElderlyFamilyMemberDto;
import com.zzyl.nursing.dto.QueryDeviceDataRequest;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceInfoVo;
import com.zzyl.nursing.vo.FamilyMemberVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.health.HealthDataVo;
import com.zzyl.nursing.vo.health.HeartRateData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;




    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     *绑定家人
     *
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody ElderlyFamilyMemberDto  elderfamilyDto){
        int result = familyMemberService.insertFamilyMemberElder(elderfamilyDto);
        if(result > 0){
            return success();
        }
        return error();
    }

    /**
     * 查询家人列表
     * @return
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult getMyElder(){

        List<FamilyMemberVo> familyMembers = familyMemberService.selectFamilyMemberLists();
        return success();
    }

    /**
     * 分页查询家人列表
     */
    @GetMapping("/list-by-page")
    public AjaxResult list(Integer pageNum,Integer pageSize) {
        List<DeviceInfoVo> familyMemberList = familyMemberService.list(pageNum, pageSize);
        return success(familyMemberList);
    }

    /**
     * 查询健康数据(新版)
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据(新版)")
    public AjaxResult queryServiceProperties(@PathVariable String iotId) {
        List<HeartRateData> heartRateData = familyMemberService.queryServiceProperties(iotId);
        return success(heartRateData);
    }



    /**
     * 按天统计查询指标数据
     * @param
     * @return List<HealthDataVo>
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(QueryDeviceDataRequest request) {
        List<HealthDataVo> healthDataVoList = familyMemberService.queryDeviceDataListByDay(request);
        return success(healthDataVoList);
    }





}
